package com.cxs.controller;

import com.cxs.model.Answers;
import com.cxs.service.AnswersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Date;

/*
 * @Author:cxs
 * @Date:2021/10/3  17:25
 * @Version 1.0
 * @Motto:放下杂念,只为迎接明天更好的自己
 * */
@Controller
@RequestMapping("/answer")
public class AnswerController {

    @Autowired
    private AnswersService answersService;

    @RequestMapping("/add")
    public String add(Integer id,String result, Model model){
        if(id == null || result == null){
            model.addAttribute("msg","参数传递异常");
            return "message";
        }

        Answers answers = new Answers();
        answers.setQid(id);
        answers.setAnsContent(result.trim());
        answers.setAnsDate(new Date());

        int i = answersService.add(answers);
        return "forward:/question/questionDetail?id=" + id;
    }
}
